package main

import (
	"net/http"
	"os"
	"os/exec"
   
	"github.com/gin-gonic/gin"
	"fmt"
)

func main() {
	router := gin.Default()

	router.GET("/", func(c *gin.Context) {
		c.String(200, "hello world")
		return
	})

	router.POST("/tms-server", func(c *gin.Context) {
		logInfo, err := RunCmd("cd /data/go/src/tms-server && ./restart.sh && ./restart-admin.sh")
		if err != nil {
			c.Error(err)
			return
		}
		c.String(200, string(logInfo))
	})

	err := http.ListenAndServe(":9021", router)
	fmt.Println(err)
}

func RunCmd(cmdStr string) (logInfo []byte, err error) {
	cmd := exec.Command("zsh", "-c", cmdStr)
	cmd.Stderr = os.Stdout
	logInfo, err = cmd.Output()
	return
}
